//
//  Person.m
//  SharedPerson
//
//  Created by qianfeng on 15/9/12.
//  Copyright (c) 2015年 wangli. All rights reserved.
//

#import "Person.h"

static Person *person=nil;

@implementation Person

//arc 下利用gcd创建单例对象
+(id)sharedPerson2
{
    static dispatch_once_t once=0;
    static id _sharedObject=nil;
    dispatch_once(&once, ^{
        _sharedObject=[[self alloc] init];
    });
    return _sharedObject;
}



+(Person *)sharedPerson
{
    //考虑线程安全
    @synchronized(self)
    {
        if(person==nil)
        {
            person=[[self alloc] init];
        }
    }
    return person;
}

+(id)allocWithZone:(struct _NSZone *)zone
{
    @synchronized(self)
    {
        if(person==nil)
        {
            person=[super allocWithZone:zone];
        }
    }
    return person;
}

-(id)copyWithZone:(NSZone *)zone
{
    return self;
}



-(instancetype)retain
{
    return self;
}
-(NSUInteger)retainCount
{
    return UINT_MAX;
}
-(oneway void)release
{
}
-(instancetype)autorelease
{
    return self;
}
@end
